﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Resources;
using System.Globalization;

using TrainingCenterSystem;
using TrainingCenterSystem.UserManagement;
using TrainingCenterSystem.VocabularyManagement;

namespace TrainingCenterWinClient.Forms
{
    public partial class MainForm : Form
    {
        #region private members
        private TrainingCenter _trainingCenter;

        private CollectionHandler _collectionHandler;

        private Form _rootForm;
        #endregion

        #region constructor(s)
        public MainForm(TrainingCenter trainingCenter, Form rootForm)
        {
            _rootForm = rootForm;
            _trainingCenter = trainingCenter;
            _collectionHandler = new CollectionHandler();

            InitializeComponent();
            this.initForm();
            this.UpdateLanguage(_trainingCenter.CurrentLanguageID);
        }
        #endregion

        private void UpdateLanguage(string langID)
        {
            try
            {
                // Set Language
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(langID);

                // Init ResourceManager
                ResourceManager resMgr =
                    new ResourceManager("TrainingCenterWinClient.ReStrings",
                    typeof(MainForm).Assembly);

                // assign localized strings to UI                
                this.Text = resMgr.GetString("MainForm_caption");
                this.grpCollections.Text = resMgr.GetString("MainForm_grpCollection");
                this.grpTests.Text = resMgr.GetString("MainForm_grpTests");                
                this.grpUsers.Text = resMgr.GetString("MainForm_grpUsers");                
                this.btnCollection.Text = resMgr.GetString("MainForm_btnCreateCollection");
                this.btnTest.Text = resMgr.GetString("MainForm_btnTest");
                this.btnUser.Text = resMgr.GetString("MainForm_btnUser");                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void initForm()
        {
            if (_trainingCenter.IsBasicVersion)
            {
                this.grpUsers.Enabled = false;
                return;
            }

            if (_trainingCenter.CurrentUser is Student)
                this.grpUsers.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            _rootForm.Dispose();
        }

        private void btnCreateCollection_Click(object sender, EventArgs e)
        {
            CollectionForm collForm = new CollectionForm(_trainingCenter,_collectionHandler);
            collForm.ShowDialog();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            TestMainForm testForm = new TestMainForm(_trainingCenter, _collectionHandler);
            testForm.ShowDialog();
        }

        private void grpUsers_Enter(object sender, EventArgs e)
        {

        }
    }
}
